#include <algorithm>
#include <cstdio>

typedef unsigned long long ull;
int t, n, m, k;
ull sum;

inline ull qpow(ull base, int exp) {
  ull res = 1;
  while (exp) {
    if (exp & 1) res = res * base % sum;
    base = base * base % sum;
    exp >>= 1;
  }
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("scramble.in", "r", stdin);
  freopen("scramble.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d", &n, &m, &k);
    sum = n + m;
    ull tmp = m * qpow(2, k) % sum;
    printf("%llu\n", std::min(tmp, sum - tmp));
  }
  return 0;
}